from selenium.webdriver.common.by import By

from base.base import Base
import page
from base.get_logger import GetLogger

logger = GetLogger.get_logger()
class PageCalc(Base):

    def page_num_click(self, num):
        for i in str(num):
            logger.info("正在点击元素{}".format(i))
            num_element = "#simple{}".format(i)
            cal_num = By.CSS_SELECTOR,num_element
            self.base_click(cal_num)

    def page_add_click(self):
        logger.info("正在点击加号元素")
        self.base_click(page.CAL_ADD)

    def page_equal_click(self):
        logger.info("正在点击等号元素")
        self.base_click(page.CAL_EQUAL)

    def page_clear_click(self):
        logger.info("正在点击清除元素")
        self.base_click(page.CAL_CLEAR)

    def page_get_result(self):
        logger.info("正在获取结果元素的值")
        return self.base_get_result(page.CAL_RESULT)

    def page_test_add(self, num1, num2):
        self.page_clear_click()
        self.page_num_click(num1)
        self.page_add_click()
        self.page_num_click(num2)
        self.page_equal_click()
        return self.page_get_result()
